package com.yc.javaee.servlet.d0615;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SessioniServlet", value = "/addSession.s")
public class AddSessioniServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 存储数据到 会话 对象中
        // 从请求中获取会话对象
        HttpSession session = request.getSession();
        // 添加数据到请求中
        request.setAttribute("language", "java");
        // 添加数据到会话中
        session.setAttribute("animal", "cat");
        // 添加数据到应用上下文对象中
        ServletContext application = this.getServletContext();
        application.setAttribute("computer", "dell");

        response.setContentType("text/html;charset=utf-8");
        response.getWriter().append("添加数据到会话中成功!");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
